import request from "./request";


const GetArticleList = async (limit, offset) => {
    return await request({
        url: `/api/blog/article_list?limit=${limit}&offset=${offset}`,
        method: "post",
    })
}

const CreateArticle = async (data) => {
    return await request({
        url: '/api/blog/create_article',
        method: 'post',
        data: data
    })
}


const GetArticleWithTagsList = async (limit, offset, category) => {
    return await request({
        url: `/api/blog/article_with_tags_list?limit=${limit}&offset=${offset}&category=${category}`,
        method: "post",
    })
}

// 新增：创建分类API(一个中文，一个英文)
const GetMyArticleWithTagsList = async (limit, offset, user_id) => {
    return await request({
        url: `/api/blog/article_with_tags_list_for_private?limit=${limit}&offset=${offset}&user_id=${user_id}`,
        method: 'post',
    })
}

const GetArticleDetail = async (id) => {
    return await request({
        url: '/api/blog/get_article_detail',
        method: "post",
        data: {
            id: id
        }
    })
}

const GetArticleDetailWithTagDetail = async (id) => {
    return await request({
        url: '/api/blog/article_with_tag_detail',
        method: "post",
        data: {
            id: id
        }
    })
}

const UpdateArticle = async (data) => {
    return await request({
        url: '/api/blog/update_article',
        method: "post",
        data: data
    })
}

const GetCategoryList = async (limit, offset, name) => {
    return await request({
        url: `/api/category/get_category_list?limit=${limit}&offset=${offset}&name=${name}`,
        method: "post",
    })
}

const GetTagList = async (limit, offset, name) => {
    return await request({
        url: `/api/tag/get_tag_list?limit=${limit}&offset=${offset}&name=${name}`,
        method: "post",
    })
}

// 新增：创建分类API(一个中文，一个英文)
const CreateCategory = async (data) => {
    return await request({
        url: '/api/category/create',
        method: 'post',
        data: data
    })
}

// 新增：创建分类API(一个中文，一个英文)
const CreateTag = async (data) => {
    return await request({
        url: '/api/tag/create',
        method: 'post',
        data: data
    })
}


// es搜索功能
const EsSearchArticles = async (data) => {
    return await request({
        url: '/api/es_blog/search',
        method: 'post',
        data: data
    })
}

// 获取热门文章get_hot_article
const GetHotArticleList = async () => {
    return await request({
        url: '/api/blog/get_hot_article',
        method: "post",
    })
}



// 新增：更新分类API
const UpdateCategory = async (data) => {
    return await request({
        url: '/api/category/update',
        method: 'post',
        data: data
    })
}

// 新增：更新标签API
const UpdateTag = async (data) => {
    return await request({
        url: '/api/tag/update',
        method: 'post',
        data: data
    })
}

// 在export default中添加这两个API
export default {
    GetArticleList,
    GetArticleWithTagsList,
    GetMyArticleWithTagsList,
    GetArticleDetail,
    GetCategoryList,
    GetTagList,
    GetArticleDetailWithTagDetail,
    UpdateArticle,
    CreateCategory,
    CreateTag,
    UpdateCategory,
    UpdateTag,
    EsSearchArticles,
    CreateArticle,
    GetHotArticleList
}